<div class="layui-container">
    <div class="layui-row">
		<div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
				<div class="widget-head">
					<div class="widget-title ">订单详情</div>
				</div>
			<div class="layui-col-md12 layui-col-xs12 widget-body">
                <div class="widget__order-detail layer-margin-bottom-lg">
                    <div class="layui-col-sm12">
                        <?php
                        // 计算当前步骤位置
                        $progress = 2;
                        $detail['pay_status']['value'] === 20 && $progress += 1;
                        $detail['delivery_status']['value'] === 20 && $progress += 1;
                        $detail['receipt_status']['value'] === 20 && $progress += 1;
                        // $detail['order_status']['value'] === 30 && $progress += 1;
                        ?>
                        <ul class="order-detail-progress progress-{$progress}">
                            <li>
                                <span>下单时间</span>
                                <div class="tip">{$detail['create_time']}</div>
                            </li>
                            <li>
                                <span>付款</span>
                                {if $detail['pay_status']['value'] heq 20}
                                    <div class="tip">
                                        付款于 <?= date('Y-m-d H:i:s', $detail['pay_time']) ?>
                                    </div>
                                {/if}
                            </li>
                            <li>
                                <span>发货</span>
                                {if $detail['delivery_status']['value'] heq 20}
                                    <div class="tip">
                                        发货于 <?= date('Y-m-d H:i:s', $detail['delivery_time']) ?>
                                    </div>
                               {/if}
                            </li>
                            <li>
                                <span>收货</span>
                               {if $detail['receipt_status']['value'] heq 20}
                                    <div class="tip">
                                        收货于<?= date('Y-m-d H:i:s', $detail['receipt_time']) ?> 
                                    </div>
                                {/if}
                            </li>
                            <li>
                                <span>完成</span>
                                {if $detail['order_status']['value'] heq 30}
                                    <div class="tip">
                                        完成于 <?= date('Y-m-d H:i:s', $detail['receipt_time']) ?>
                                    </div>
                                {/if}
                            </li>
                        </ul>
                    </div>

                    <div class="widget-head layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <div class="widget-title">基本信息</div>
                    </div>
                    <div class="layer-scrollable-horizontal">
                        <table width="100%" class="layui-table">
                            <tbody>
                            <tr>
                                <th>订单号</th>
                                <th>买家</th>
                                <th>订单金额</th>
                                <th>交易状态</th>
                                {if ($detail['pay_status']['value'] heq 10 && $detail['order_status']['value'] === 10)}
                                    <th>操作</th>
                                {/if}
                            </tr>
                            <tr>
                                <td>{$detail['order_no']}</td>
                                <td>
                                    <p>{$detail['user']['nickName']}</p>
                                    <p class="layer-link-muted">(用户id：{$detail['user']['user_id']})</p>
                                </td>
                                <td class="">
                                    <div class="td__order-price layer-text-left">
                                        <ul class="layer-avg-sm-2">
                                            <li class="layer-text-right">订单总额：</li>
                                            <li class="layer-text-right">￥{$detail['total_price']} </li>
                                        </ul>
                                        {if ($detail['coupon_id'] > 0)}
                                            <ul class="layer-avg-sm-2">
                                                <li class="layer-text-right">优惠券抵扣：</li>
                                                <li class="layer-text-right">- ￥{$detail['coupon_price']}</li>
                                            </ul>
                                       {/if}
                                        <ul class="layer-avg-sm-2">
                                            <li class="layer-text-right">运费金额：</li>
                                            <li class="layer-text-right">+ ￥{$detail['express_price']}</li>
                                        </ul>
                                        {if $detail['update_price']['value'] !== '0.00'}
                                            <ul class="layer-avg-sm-2">
                                                <li class="layer-text-right">后台改价：</li>
                                                <li class="layer-text-right">{$detail['update_price']['symbol']}
                                                    ￥{$detail['update_price']['value']}</li>
                                            </ul>
                                        {/if}
                                        <ul class="layer-avg-sm-2">
                                            <li class="layer-text-right">实付款金额：</li>
                                            <li class="x-color-red layer-text-right">
                                                ￥{$detail['pay_price']}</li>
                                        </ul>
                                    </div>
                                </td>
                                <td>
                                    <p>付款状态：
                                        <span class="layer-badge
                                        {$detail['pay_status']['value'] === 20 ? 'layer-badge-success' : ''}">
                                                {$detail['pay_status']['text']}</span>
                                    </p>
                                    <p>发货状态：
                                        <span class="layer-badge
                                        {$detail['delivery_status']['value'] === 20 ? 'layer-badge-success' : ''}">
                                                {$detail['delivery_status']['text']}</span>
                                    </p>
                                    <p>收货状态：
                                        <span class="layer-badge
                                       {$detail['receipt_status']['value'] === 20 ? 'layer-badge-success' : ''}">
                                                {$detail['receipt_status']['text']}</span>
                                    </p>
                                </td>
                                {if ($detail['pay_status']['value'] === 10 && $detail['order_status']['value'] === 10)}
                                    <td>
                                        <p class="layer-text-center">
                                            <a class="j-update-price" href="javascript:void(0);"
                                               data-order_id="{$detail['order_id']}"
                                               data-order_price="{$detail['total_price'] - $detail['coupon_price'] + $detail['update_price']['value']}"
                                               data-express_price="{$detail['express_price']}">修改价格</a>
                                        </p>
                                    </td>
                                {/if}
                            </tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="widget-head layer-cf">
                        <div class="widget-title layer-fl">商品信息</div>
                    </div>
                    <div class="layer-scrollable-horizontal">
                        <table width="100%" class="layui-table">
                            <tbody>
                            <tr>
                                <th>商品名称</th>
                                <th>商品编码</th>
                                <th>重量(Kg)</th>
                                <th>单价</th>
                                <th>购买数量</th>
                                <th>商品总价</th>
                            </tr>
                            {foreach $detail['goods'] as $Item}
                                <tr>
                                    <td class="goods-detail layer-text-middle">
                                        <div class="goods-image">
                                            <img src="{$Item['image']}" alt="">
                                        </div>
                                        <div class="goods-info">
                                            <p class="goods-title">{$Item['name']}</p>
                                            <p class="goods-spec layer-link-muted">
                                                {$Item['goods_attr']}
                                            </p>
                                        </div>
                                    </td>
                                    <td>{$Item['goods_no'] ?: '--' }</td>
                                    <td>{$Item['goods_weight'] ?: '--'}</td>
                                    <td>￥{$Item['goods_price']}</td>
                                    <td>×{$Item['total_num']}</td>
                                    <td>￥{$Item['total_price']}</td>
                                </tr>
                            {/foreach}
                            <tr>
                                <td colspan="6" class="layer-text-right layer-cf">
                                    <span class="layer-fl">买家留言：{$detail['buyer_remark'] ?: '无' }</span>
                                    <span class="layer-fr">总计金额：￥{$detail['total_price']}</span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="widget-head layer-cf">
                        <div class="widget-title layer-fl">收货信息</div>
                    </div>
                    <div class="layer-scrollable-horizontal">
                        <table width="100%" class="layui-table">
                            <tbody>
                            <tr>
                                <th>收货人</th>
                                <th>收货电话</th>
                                <th>收货地址</th>
                            </tr>
                            <tr>
                                <td>{$detail['address']['name']}</td>
                                <td>{$detail['address']['phone']}</td>
                                <td>
                                    {$detail['address']['region']['province']}
                                    {$detail['address']['region']['city']}
                                   {$detail['address']['region']['region']}
                                    {$detail['address']['detail']}
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

                   {if $detail['pay_status']['value'] heq 20}
                        <div class="widget-head layer-cf">
                            <div class="widget-title layer-fl">付款信息</div>
                        </div>
                        <div class="layer-scrollable-horizontal">
							<table width="100%" class="layui-table">
                                <tbody>
                                <tr>
                                    <th>应付款金额</th>
                                    <th>支付方式</th>
                                    <th>支付流水号</th>
                                    <th>付款状态</th>
                                    <th>付款时间</th>
                                </tr>
                                <tr>
                                    <td>￥{$detail['pay_price']}</td>
                                    <td>微信支付</td>
                                    <td>{$detail['transaction_id'] ?: '--'}</td>
                                    <td>
                                        <span class="layer-badge
                                        {$detail['pay_status']['value'] === 20 ? 'layer-badge-success' : ''}">
                                                {$detail['pay_status']['text']}</span>
                                    </td>
                                    <td>
                                        {$detail['pay_time'] ? date('Y-m-d H:i:s', $detail['pay_time']) : '--'}
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    {/if}

                    {if $detail['pay_status']['value'] === 20}
                        <div class="widget-head layer-cf">
                            <div class="widget-title layer-fl">发货信息</div>
                        </div>

                        {if $detail['delivery_status']['value'] === 10}
                            <!-- 去发货 -->
                            <form id="delivery" class="my-form layer-form tpl-form-line-form" method="post"
                                  action="{:url('order/delivery', ['order_id' => $detail['order_id']])}">
                                <div class="layer-form-group">
                                    <label class="layui-col-sm3 layui-col-lg2 layer-form-label form-require">物流公司 </label>
                                    <div class="layui-col-sm9 layer-u-end layer-padding-top-xs">
                                        <select name="order[express_id]"
                                                data-am-selected="{btnSize: 'sm', maxHeight: 240}" required>
                                            <option value=""></option>
                                            {if (isset($express_list))}{foreach $express_list as $expres}
                                                <option value="{$expres['express_id']}">
                                                    {$expres['express_name']}</option>
                                            {/foreach} {/if}
                                        </select>
                                        <div class="help-block layer-margin-top-xs">
                                            <small>可在 <a href="{:url('setting/express')}" target="_blank">物流公司列表</a>
                                                中设置
                                            </small>
                                        </div>
                                    </div>
                                </div>
                                <div class="layer-form-group">
                                    <label class="layui-col-sm3 layui-col-lg2 layer-form-label form-require">物流单号 </label>
                                    <div class="layui-col-sm9 layer-u-end">
                                        <input type="text" class="tpl-form-input" name="order[express_no]" required>
                                    </div>
                                </div>
                                <div class="layer-form-group">
                                    <div class="layui-col-sm9 layui-col-smpush-3 layer-margin-top-lg">
                                        <button type="submit" class="j-submit layer-btn layer-btn-sm layer-btn-secondary">
                                            确认发货
                                        </button>
                                    </div>
                                </div>
                            </form>
                        {else/}
                            <div class="layer-scrollable-horizontal">
                                <table class="regional-table layer-table layer-table-bordered layer-table-centered
                                layer-text-nowrap layer-margin-bottom-xs">
                                    <tbody>
                                    <tr>
                                        <th>物流公司</th>
                                        <th>物流单号</th>
                                        <th>发货状态</th>
                                        <th>发货时间</th>
                                    </tr>
                                    <tr>
                                        <td>{$detail['express']['express_name']}</td>
                                        <td>{$detail['express_no']}</td>
                                        <td>
                                             <span class="layer-badge
                                            {$detail['delivery_status']['value'] === 20 ? 'layer-badge-success' : ''}">
                                                   {$detail['delivery_status']['text']}</span>
                                        </td>
                                        <td>
                                            <?= date('Y-m-d H:i:s', $detail['delivery_time']) ?>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        {/if} {/if}
					</div>
                </div>
            </div>

        </div>
    </div>
</div>

<script id="tpl-update-price" type="text/template">
    <div class="layer-padding-top-sm">
        <form class="form-update-price layer-form tpl-form-line-form" method="post"
              action="{:url('order/updatePrice', ['order_id' => $detail['order_id']])}">
            <div class="layer-form-group">
                <label class="layui-col-sm3 layer-form-label"> 订单金额 </label>
                <div class="layui-col-sm9">
                    <input type="number" min="0.00" class="tpl-form-input" name="order[update_price]"
                           value="{{ order_price }}">
                    <small>最终付款价 = 订单金额 + 运费金额</small>
                </div>
            </div>
            <div class="layer-form-group">
                <label class="layui-col-sm3 layer-form-label"> 运费金额 </label>
                <div class="layui-col-sm9">
                    <input type="number" min="0.00" class="tpl-form-input" name="order[update_express_price]"
                           value="{{ express_price }}">
                </div>
            </div>
        </form>
    </div>
</script>

<script>
    $(function () {

        /**
         * 修改价格
         */
        $('.j-update-price').click(function () {
            var $this = $(this);
            var data = $this.data();
            // var orderId = $(this).data('order_id');
            layer.open({
                type: 1
                , title: '订单价格修改'
                , area: '340px'
                , offset: 'auto'
                , anim: 1
                , closeBtn: 1
                , shade: 0.3
                , btn: ['确定', '取消']
                , content: template('tpl-update-price', data)
                , success: function (layero) {

                }
                , yes: function (index) {
                    // console.log('asdasd');
                    // 表单提交
                    $('.form-update-price').ajaxSubmit({
                        type: "post",
                        dataType: "json",
                        success: function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        }
                    });
                    layer.close(index);
                }
            });
        });

        /**
         * 表单验证提交
         * @type {*}
         */
        $('.my-form').superForm();

    });
</script>
